﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Albon.Model;
using Commonlib;

namespace DAL
{
    public class PayMethodDAL
    {

        /// <summary>
        /// 添加（id=0）/修改(id!=0)一种付款方式
        /// </summary>
        public bool alterPayMethod(PayMethod paymethod)
        {
            SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.Int,4),
					new SqlParameter("@methodName", SqlDbType.VarChar,50),
					new SqlParameter("@percentage", SqlDbType.Decimal,9),
					new SqlParameter("@remark", SqlDbType.Text)};
            parameters[0].Value = paymethod.ID;
            parameters[1].Value = paymethod.methodName;
            parameters[2].Value = paymethod.percentage;
            parameters[3].Value = paymethod.remark;
            return SqlHelper.ExecuteNonQuery(SqlHelper.SqlConnectionString,CommandType.StoredProcedure,"p_paymethodalter",parameters)==1;
        }

        /// <summary>
        /// 删除一条付款方式信息
        /// </summary>
        public bool delPayMethod(int id)
        {
            string cmdstr = "delete from PayMethod where id="+id;
            return  SqlHelper.ExecuteNonQuery(SqlHelper.SqlConnectionString,CommandType.Text,cmdstr,null)==1;
        }

        /// <summary>
        /// 根据 名字 获取付款方式信息
        /// </summary>
        public DataTable getPayMethod(string methodname)
        {
            string cmdstr = "select * from PayMethod where methodName ='"+methodname+"'";
            return SqlHelper.ExecuteDataSet(SqlHelper.SqlConnectionString,CommandType.Text,cmdstr,null).Tables[0];
        }
    }
}
